package create;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.border.EmptyBorder;

import database.Teacher;

import javax.swing.JLabel;
import javax.swing.JOptionPane;

import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.JRadioButton;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.ActionEvent;

public class TeaInfo extends JFrame {
	Teacher t = new Teacher();
	private JPanel contentPane;
	private JPasswordField pwd;
	private JTextField teacherId;
	private JTextField name;
	private JTextField schoolDepartment;
	private JTextField tel;
	private int sexFlag;
	private int positionFlag;
	private String password;
	private int flag = 2;//鉴别老师还是学生
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					TeaInfo frame = new TeaInfo();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public TeaInfo() {
		setVisible(true);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(600, 300, 734, 482);
		setLocationRelativeTo(getOwner());
		setResizable(false);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel label = new JLabel("教师信息");
		label.setFont(new Font("Lucida Grande", Font.PLAIN, 25));
		label.setBounds(306, 27, 106, 31);
		contentPane.add(label);
		
		JLabel lblNewLabel = new JLabel("管理员密码");
		lblNewLabel.setBounds(53, 106, 74, 23);
		contentPane.add(lblNewLabel);
		
		JLabel label_1 = new JLabel("教工号");
		label_1.setBounds(53, 154, 74, 23);
		contentPane.add(label_1);
		
		JLabel label_2 = new JLabel("性别");
		label_2.setBounds(53, 263, 74, 23);
		contentPane.add(label_2);
		
		JLabel label_3 = new JLabel("姓名");
		label_3.setBounds(53, 209, 74, 23);
		contentPane.add(label_3);
		
		JLabel label_4 = new JLabel("职称");
		label_4.setBounds(338, 106, 74, 23);
		contentPane.add(label_4);
		
		JLabel label_5 = new JLabel("所属院系");
		label_5.setBounds(338, 154, 74, 23);
		contentPane.add(label_5);
		
		JLabel label_6 = new JLabel("电话");
		label_6.setBounds(338, 209, 74, 23);
		contentPane.add(label_6);
		
		pwd = new JPasswordField();
		pwd.setBounds(151, 104, 130, 26);
		contentPane.add(pwd);
		pwd.setColumns(10);
		
		teacherId = new JTextField();
		teacherId.setColumns(10);
		teacherId.setBounds(151, 152, 130, 26);
		contentPane.add(teacherId);
		teacherId.addKeyListener(new KeyAdapter(){  
            public void keyTyped(KeyEvent e) {  
                int keyChar = e.getKeyChar();                 
                if(keyChar >= KeyEvent.VK_0 && keyChar <= KeyEvent.VK_9){  
                }else{  
                    e.consume();   
                }  
            }  
        }); 
		
		
		name = new JTextField();
		name.setColumns(10);
		name.setBounds(151, 207, 130, 26);
		contentPane.add(name);
		
		schoolDepartment = new JTextField();
		schoolDepartment.setColumns(10);
		schoolDepartment.setBounds(424, 152, 130, 26);
		contentPane.add(schoolDepartment);
		
		tel = new JTextField();
		tel.setColumns(10);
		tel.setBounds(424, 207, 130, 26);
		contentPane.add(tel);
		
		JRadioButton radioButton = new JRadioButton("男");
		radioButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				sexFlag = 1;
			}
		});
		radioButton.setBounds(115, 262, 50, 23);
		contentPane.add(radioButton);
		
		JRadioButton rdbtnNewRadioButton = new JRadioButton("女");
		rdbtnNewRadioButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				sexFlag = 2;
			}
		});
		rdbtnNewRadioButton.setBounds(188, 262, 57, 23);
		contentPane.add(rdbtnNewRadioButton);
		
		ButtonGroup b = new ButtonGroup();
		b.add(rdbtnNewRadioButton);
		b.add(radioButton);
		
		
		
		JRadioButton radioButton_1 = new JRadioButton("教授");
		radioButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				positionFlag = 1;
			}
		});
		radioButton_1.setBounds(393, 105, 58, 23);
		contentPane.add(radioButton_1);
		
		JRadioButton radioButton_2 = new JRadioButton("副教授");
		radioButton_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				positionFlag = 2;
			}
		});
		
		radioButton_2.setBounds(463, 105, 74, 23);
		contentPane.add(radioButton_2);
		
		JRadioButton radioButton_3 = new JRadioButton("教师");
		radioButton_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				positionFlag = 3;
			}
		});
		radioButton_3.setBounds(549, 105, 74, 23);
		contentPane.add(radioButton_3);
		
		ButtonGroup b1 = new ButtonGroup();
		b1.add(radioButton_1);
		b1.add(radioButton_2);
		b1.add(radioButton_3);
		
		
		JButton next = new JButton("下一步");
		next.addActionListener(new ActionListener() {
			@SuppressWarnings("deprecation")
			public void actionPerformed(ActionEvent e) {
				System.out.println(pwd.getText());
				if(!pwd.getText().equals("windy")){
					JOptionPane.showMessageDialog(null,"管理员密码错误，请联系管理员","信息提示框",JOptionPane.INFORMATION_MESSAGE);
					new CreateUser();
					setVisible(false);
				}else{
					t.setTeacherID(Integer.parseInt(teacherId.getText()));
					t.setName(name.getText());
					if(positionFlag == 1){
						t.setPosition("教授");
					}else if(positionFlag == 2){
						t.setPosition("副教授");
					}else if(positionFlag == 3){
						t.setPosition("教师");
					}
					t.setSchool_department(schoolDepartment.getText());
					t.setTeliPhone(Integer.parseInt((tel.getText())));
					if(sexFlag == 1){
						t.setSex("男");
					}else if(sexFlag == 2){
						t.setSex("女");
					}
					new Create().InputTeaInfo(t);
					new PwdInfo(flag,Integer.parseInt(teacherId.getText()));
					setVisible(false);
				}
			}
		});
		next.setBounds(549, 373, 117, 29);
		contentPane.add(next);
		
		JButton clear = new JButton("清空");
		clear.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				new TeaInfo();
				setVisible(false);
			}
		});
		clear.setBounds(368, 373, 117, 29);
		contentPane.add(clear);
		
		JButton privious = new JButton("上一步");
		privious.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				new CreateUser();
				setVisible(false);
			}
		});
		privious.setBounds(188, 373, 117, 29);
		contentPane.add(privious);
	}
}
